package cn.fl.ref.fncpreabslim.controller;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;







import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.pdf.PdfStructTreeController.returnType;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.ref.fncpreabslim.service.IFncPreAbsLimService;
import cn.fl.ref.fncpreabslim.vo.FncPreAbsLimVO;
import cn.fl.ref.fncpreabslimrec.service.IFncPreAbsLimRecService;
import cn.fl.ref.fncpreabslimrec.vo.FncPreAbsLimRecVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.BankAccInfoVO;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import fl.ref.fncpreabslim.condition.FncPreAbsLimQueryCondition;
import fl.ref.fncpreabslimrec.condition.FncPreAbsLimRecQueryCondition;
import fl.ref.fribaseinfo.condition.BankAccInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import fl.ref.fribaseinfo.dto.BankAccInfoDTO;
import fl.ref.fribaseinfo.service.IBankAccInfoApiService;



/**
 * @Description: 融资机构PRE-ABS额度表
 */
@Controller
@RequestMapping("/rfbuss/fncpreabslim")
public class FncPreAbsLimController extends BaseController {

	
	private static final Logger logger = LoggerFactory.getLogger(FncPreAbsLimController.class);
	@Autowired
	IFncPreAbsLimService fncPreAbsLimService;
	/**
	 * 融资机构银行帐号信息
	 */
	@Autowired
	private IBankAccInfoApiService bankAccInfoApiService;
	
	@Autowired
	private IFriBaseInfoService friBaseInfoService;
	
	@Autowired
	IFncPreAbsLimRecService fncPreAbsLimRecService;
	
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		
		String id  = request.getParameter("id");
		if (StringUtils.isNotBlank(request.getParameter("accId"))) {
			ModelAndView view = new ModelAndView("/rfbuss/fncpreabslim/fncPreAbsLimListAcc");
			BankAccInfoVO vo = this.friBaseInfoService.selectAccById(Long.valueOf(request.getParameter("accId")), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			view.addObject("vo", vo);
			return view;
		}
		ModelAndView view = new ModelAndView("/rfbuss/fncpreabslim/fncPreAbsLimList");
		//FncPreAbsLimVO vo = this.fncPreAbsLimService.selectById(Long.parseLong(id));
		FriBaseInfoVO friBaseInfoVO= this.friBaseInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
		view.addObject("id", id);
		view.addObject("friBaseInfoVO", friBaseInfoVO);
		return view;
	}
	
	/**
	 * 初始化列表
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
	
	
		String id = request.getParameter("id");
	
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		FncPreAbsLimQueryCondition qc=new FncPreAbsLimQueryCondition();
		if (StringUtils.isNotEmpty(id)) {
			qc.setInsAccNoId(Long.parseLong(id));
		}
		if (StringUtils.isNotEmpty(request.getParameter("insId"))) {
			qc.setInsId(Long.parseLong(request.getParameter("insId")));
		}		
		page.setCondition(qc);
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		Pager pager = this.fncPreAbsLimService.searchListPage(page);
		List<FncPreAbsLimVO> list = (List<FncPreAbsLimVO>) pager.getResultList();
		ListPageVO<FncPreAbsLimVO> listPage = new ListPageVO<FncPreAbsLimVO>(list, pager.getTotalCount());

		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 到额度管理页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String accId  = request.getParameter("id");
		BankAccInfoDTO dto=this.bankAccInfoApiService.selectById(Long.parseLong(accId), CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd());
		ModelAndView view = new ModelAndView("/rfbuss/fncpreabslim/fncPreAbsLimAdd");
		//FncPreAbsLimVO vo = this.fncPreAbsLimService.selectById(Long.parseLong(id));
		//List<KeyValueVO> limTypCdlist=new ArrayList<KeyValueVO>(); //this.getKvList.getKvList("FNC0001");
		//KeyValueVO vo1 =new KeyValueVO();
		//KeyValueVO vo2 =new KeyValueVO();
		//vo1.setKey("3");vo1.setValue("手工扣减");
		//vo2.setKey("4");vo2.setValue("手工归还");
		//limTypCdlist.add(vo1);
		//limTypCdlist.add(vo2);
		view.addObject("id", accId);
		view.addObject("accvo", dto);
		view.addObject("view", request.getParameter("view"));
		//view.addObject("limTypCdlist",JSON.toJSONString(limTypCdlist) );
		return view;
	}
	
	/**
	 * 到额度变化新增页面
	 */
	@RequestMapping(value = "/toAddRecPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddRecPage(HttpServletRequest request, HttpServletResponse response) {
		String LimId  = request.getParameter("id");
		
		ModelAndView view = new ModelAndView("/rfbuss/fncpreabslim/fncPreAbsLimRecAdd");
		FncPreAbsLimVO vo = this.fncPreAbsLimService.selectById(Long.parseLong(LimId));
		List<KeyValueVO> limTypCdlist=new ArrayList<KeyValueVO>(); //this.getKvList.getKvList("FNC0001");
		KeyValueVO vo1 =new KeyValueVO();
		KeyValueVO vo2 =new KeyValueVO();
		vo1.setKey("3");vo1.setValue("手工扣减");
		vo2.setKey("4");vo2.setValue("手工归还");
		limTypCdlist.add(vo1);
		limTypCdlist.add(vo2);
		view.addObject("id", LimId);
		view.addObject("limvo", vo);
		view.addObject("limTypCdlist",JSON.toJSONString(limTypCdlist) );
		return view;
	}
	
	/**
	 * 到额度变化新增页面
	 */
	@RequestMapping(value = "/toeditLimPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toeditLimPage(HttpServletRequest request, HttpServletResponse response) {
		String Limid  = request.getParameter("id");
		String accNo = request.getParameter("accNo");
		ModelAndView view = new ModelAndView("/rfbuss/fncpreabslim/fncPreAbsLimEdit");
		//FncPreAbsLimVO vo = this.fncPreAbsLimService.selectById(Long.parseLong(id));

			
		
		view.addObject("id", Limid);
		view.addObject("accNo", accNo);
		return view;
	}
	
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String insId = request.getParameter("insId");
		
		String insAccNoId = request.getParameter("insAccNoId");
		
		String accNo = request.getParameter("accNo");
		
		String batNo = request.getParameter("batNo");
		
		String preLimAmt = request.getParameter("preLimAmt");
		
		String currLimAmt = request.getParameter("currLimAmt");
		
		String isDel = request.getParameter("isDel");
		
		String crtTm = request.getParameter("crtTm");
		
		String crtUsrId = request.getParameter("crtUsrId");
		
		String mdfTm = request.getParameter("mdfTm");
		
		String mdfUsrId = request.getParameter("mdfUsrId");

		String buOrgCds = request.getParameter("buOrgCds");
		
		String payNum = request.getParameter("payNum");
		
		FncPreAbsLimVO  entity=new FncPreAbsLimVO();
		if (StringUtils.isNotEmpty(insId)) {
			entity.setInsId(Long.parseLong(insId));
		}
		if (StringUtils.isNotEmpty(insAccNoId)) {
			entity.setInsAccNoId(Long.parseLong(insAccNoId));
		}
		if (StringUtils.isNotEmpty(accNo)) {
          entity.setAccNo(accNo);
			
		}
		if (StringUtils.isNotEmpty(batNo)) {

          entity.setBatNo(batNo);
			
		}
		if (StringUtils.isNotEmpty(preLimAmt)) {
			entity.setPreLimAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(preLimAmt)));
			entity.setCurrLimAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(preLimAmt)));
		}
		if (StringUtils.isNotEmpty(currLimAmt)) {
			
		}
		if (StringUtils.isNotEmpty(isDel)) {
			
		}
		if (StringUtils.isNotEmpty(crtTm)) {
			
		}
		if (StringUtils.isNotEmpty(crtUsrId)) {
			
		}
		if (StringUtils.isNotEmpty(mdfTm)) {
			
		}
		if (StringUtils.isNotEmpty(mdfUsrId)) {
			
		}
		if (StringUtils.isNotEmpty(buOrgCds)) {
			entity.setBuOrgCds(buOrgCds);
		}
		if (StringUtils.isNotEmpty(payNum)) {
			entity.setPayNum(Long.valueOf(payNum));
		}
		entity.setCrtTm(new Date());
		//entity.setIsvalid(BaseConstant.IS_YESNO_YES); // 有效
		entity.setIsDel(BaseConstant.IS_YESNO_NO); // 未删除
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		
		try {
			FncPreAbsLimQueryCondition limqc = new FncPreAbsLimQueryCondition();
			limqc.setBatNo(batNo);
			List<FncPreAbsLimVO> limvo=this.fncPreAbsLimService.searchList(limqc);
			if(limvo.size()>0){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"该批次号已存在");	
			}
			Long mainId = this.fncPreAbsLimService.add(entity);
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("新增成功!");
			BaseLogUtils.info(logger, "add", "新增数据 ", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "add", "新增数据失败"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 修改
	 */
	@RequestMapping(value = "/edit.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object edit(HttpServletRequest request, HttpServletResponse response) throws Exception {
String limId = request.getParameter("limId");

//String insAccNoId = request.getParameter("insAccNoId");

//String accNo = request.getParameter("accNo");

//String batNo = request.getParameter("batNo");

String preLimAmt = request.getParameter("preLimAmt");

//String currLimAmt = request.getParameter("currLimAmt");

//String isDel = request.getParameter("isDel");

//String crtTm = request.getParameter("crtTm");

//String crtUsrId = request.getParameter("crtUsrId");

//String mdfTm = request.getParameter("mdfTm");

//String mdfUsrId = request.getParameter("mdfUsrId");


		
		FncPreAbsLimVO  entity=new FncPreAbsLimVO();
		if (StringUtils.isNotEmpty(limId)) {
			entity.setId(Long.parseLong(limId));
		}else{
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"未找到该额度信息");	
		}
        FncPreAbsLimRecQueryCondition recqc = new FncPreAbsLimRecQueryCondition();
        recqc.setLimId(Long.parseLong(limId));
        recqc.setLimTypCd("1");
		List<FncPreAbsLimRecVO> recvo= this.fncPreAbsLimRecService.searchList(recqc);
		if(recvo.size()>0){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"已有余额自动扣减操作，无法再使用该操作");	
		}
		
		if (StringUtils.isNotEmpty(preLimAmt)) {
			entity.setPreLimAmt(DecimalUtils.convertYuanToFen(Double.parseDouble(preLimAmt)));
		}
		
		 FncPreAbsLimVO absvo=this.fncPreAbsLimService.selectById(Long.parseLong(limId));
		 entity.setCurrLimAmt(absvo.getCurrLimAmt()+DecimalUtils.convertYuanToFen(Double.parseDouble(preLimAmt))-absvo.getPreLimAmt());
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		
		try {
			
			this.fncPreAbsLimService.modify(entity);
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("额度修改成功!");
			BaseLogUtils.info(logger, "edit", "额度修改 ", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "edit", "额度修改失败"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "edit", "额度修改失败"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/remove.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public DataResultVO remove(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
		try {
			this.fncPreAbsLimService.removeById(Long.parseLong(id));
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("删除成功!");
			BaseLogUtils.info(logger, "remove", "删除数据,主键["+id+"].", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "remove", "删除数据失败,主键["+id+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误!");
			BaseLogUtils.error(logger, "remove", "删除数据失败,主键["+id+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 加载金融机构收款户选择框
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/initRecvList.do" ,method = {RequestMethod.GET})
	public @ResponseBody  List<BankAccInfoDTO>  initRecvList(HttpServletRequest request, HttpServletResponse response) {
		String instid = request.getParameter("insId");

		if (StringUtils.isEmpty(instid)) {
			return null;
		}
		BankAccInfoQueryCondition bankAccInfoQC = new BankAccInfoQueryCondition();
		bankAccInfoQC.setFundRasInsId(Long.parseLong(instid));
		//bankAccInfoQC.setAccTypCd("3");
		List<String> list=new ArrayList<String>(); //显示pre跟资管付款
		list.add(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_ZG);
		list.add(FriBaseInfoConstant.BANK_ACC_INFO_ACC_TYP_CD_PRE);
		bankAccInfoQC.setAccTypCds(list);
		bankAccInfoQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
		bankAccInfoQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		List<BankAccInfoDTO> banklst = bankAccInfoApiService.searchList(bankAccInfoQC);
		
		return banklst;
	}
	
	/**
	 * 得到一条记录
	 */
	@RequestMapping(value = "/getByAccId.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String accId = request.getParameter("accId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功!");
		
		FncPreAbsLimVO limvo = new FncPreAbsLimVO();
		try {
			if (StringUtils.isNotBlank(accId)) {
				FncPreAbsLimQueryCondition qc = new FncPreAbsLimQueryCondition();
				qc.setInsAccNoId(Long.parseLong(accId));
				List<FncPreAbsLimVO> limvoList=this.fncPreAbsLimService.searchList(qc);
				if(limvoList.size()==1){
					limvo=limvoList.get(0);
				}
			}
			if (StringUtils.isNotBlank(request.getParameter("id"))) {
				limvo=this.fncPreAbsLimService.selectById(new Long(request.getParameter("id")));
			}
			result.setData(limvo);
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取数据失败,主键[" + accId + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误!");
			BaseLogUtils.error(logger, "getById", "获取数据失败,主键[" + accId + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	
	/**
	 * 初始化列表
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initRecList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initRecList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
	
	
		String limId = request.getParameter("id");
	
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		FncPreAbsLimRecQueryCondition qc=new FncPreAbsLimRecQueryCondition();
		
	
		if (StringUtils.isNotEmpty(limId)) {
			qc.setLimId(Long.parseLong(limId));
		}
		
		
		page.setCondition(qc);
		
		Pager pager = this.fncPreAbsLimRecService.searchListPage(page);
		List<FncPreAbsLimRecVO> list = (List<FncPreAbsLimRecVO>) pager.getResultList();
		this.setListVOWithDicInfo(list);
		ListPageVO<FncPreAbsLimRecVO> listPage = new ListPageVO<FncPreAbsLimRecVO>(list, pager.getTotalCount());

		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	private void setListVOWithDicInfo(List<FncPreAbsLimRecVO> listVO) {
		String sysCd=CurrentThreadContext.getCurrentSysCd();
		String orgCd="0000";
		//CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd()
		Map<String, String> limTypCd=this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd,"FNC0001");
		for (FncPreAbsLimRecVO vo : listVO) {
			if(limTypCd.containsKey(vo.getLimTypCd())){
			     vo.setLimTypCdNm(limTypCd.get(vo.getLimTypCd()));
		    } 
		}
	}
	
	
	private List<KeyValueVO> getKvList(String grpCd){
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}
	/**
	 * 可投放事业部
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getbuOrgCds.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object getbuOrgCds(HttpServletRequest request, HttpServletResponse response) {
		//可投放款项
		List<KeyValueVO> accTyp =this.getKvList("SYS0031");
		
		return accTyp;
	}
	/**
	 * 初始化列表
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initListAll.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initListAll(HttpServletRequest request, HttpServletResponse response) {
		
		FncPreAbsLimQueryCondition qc=new FncPreAbsLimQueryCondition();
		if (StringUtils.isNotEmpty(request.getParameter("insAccNoId"))) {
			qc.setInsAccNoId(Long.parseLong(request.getParameter("insAccNoId")));
		}
		if (StringUtils.isNotEmpty(request.getParameter("insId"))) {
			qc.setInsId(Long.parseLong(request.getParameter("insId")));
		}		
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		List<FncPreAbsLimVO> list = (List<FncPreAbsLimVO>) this.fncPreAbsLimService.searchList(qc);
		
		BaseLogUtils.info(logger, "initListAll", "查询数据完成. DATA:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
		return list;
	}
}

